package com.kingmed.kmss.common.utils;

import org.apache.commons.lang3.CharUtils;

/**
 * 名字转换工具
 * 如数据库字段命名转为java属性命名
 * @author wzg
 *
 *
 */
public class NameUtils {
	/**
	 * Change field name from database format to java property E.g, admin_passion ->
	 * adminPassion
	 * 
	 * @param field
	 * @return
	 */
	public static String fieldToProperty(String field) {
		if (null == field) {
			return "";
		}
		char[] chars = field.toCharArray();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < chars.length; i++) {
			char c = chars[i];
			if (c == '_') {
				int j = i + 1;
				if (j < chars.length) {
					sb.append(StringUtils.upperCase(CharUtils.toString(chars[j])));
					i++;
				}
			} else {
				sb.append(c);
			}
		}
		return sb.toString();
	}
}
